<?php

namespace app\modules\setting\models\null;

use yii\helpers\Json;

/**
 * This is the model class for table "{{%etc_office_tiktok_account}}".
 *
 * @property int $id
 * @property int $user_id 机构id，sys_adminuser.id用户id
 * @property string $name 账号名称
 * @property string $link 账号链接
 * @property string $cat 账号类目
 * @property string $weight 账号权重
 * @property string $create_at 创建时间
 */
class EtcOfficeTiktokAccount extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%etc_office_tiktok_account}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'name', 'link', 'cat', 'weight', 'create_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            
            'id' => 'ID',
            
            'user_id' => '机构id，sys_adminuser.id用户id',
            
            'name' => '账号名称',
            
            'link' => '账号链接',
            
            'cat' => '账号类目',
            
            'weight' => '账号权重',
            
            'create_at' => '创建时间',
        ];
    }


    public function beforeValidate()
    {
        foreach ($this->attributes() as $field){
            if (is_array($this->$field)){
                $this->$field = Json::encode($this->$field);
            }
        }

        return parent::beforeValidate(); // TODO: Change the autogenerated stub
    }

    public function getFirstErrorStr()
    {
        $errors = $this->getErrors();

        if ($errors){
            foreach ($errors as $item){
                return $item[0];
            }
        }

        return "";
    }
}
